// - -------------------------------------------------------------------------------------------------------------- - //
// Real //
// - -------------------------------------------------------------------------------------------------------------- - //
var Real_Sin45 = 0.70710678118654752440084436210485;
// - -------------------------------------------------------------------------------------------------------------- - //


// - -------------------------------------------------------------------------------------------------------------- - //
// Vector2D //
// - -------------------------------------------------------------------------------------------------------------- - //
function Vector2D( _x, _y ) {
	// Data //
	this.x = _x;
	this.y = _y;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Add = function( vs ) {
	this.x += vs.x;
	this.y += vs.y;
	return this;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Sub = function( vs ) {
	this.x -= vs.x;
	this.y -= vs.y;
	return this;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Mult = function( vs ) {
	this.x *= vs.x;
	this.y *= vs.y;
	return this;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Div = function( vs ) {
	this.x /= vs.x;
	this.y /= vs.y;
	return this;
}
// - -------------------------------------------------------------------------------------------------------------- - //

// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.AddScalar = function( vs ) {
	this.x += vs;
	this.y += vs;
	return this;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.SubScalar = function( vs ) {
	this.x -= vs;
	this.y -= vs;
	return this;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.MultScalar = function( vs ) {
	this.x *= vs;
	this.y *= vs;
	return this;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.DivScalar = function( vs ) {
	this.x /= vs;
	this.y /= vs;
	return this;
}
// - -------------------------------------------------------------------------------------------------------------- - //

// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Negative = function() {
	return new Vector2D( -this.x, -this.y );
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.FlipX = function() {
	return new Vector2D( -this.x, this.y );
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.FlipY = function() {
	return new Vector2D( this.x, -this.y );
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Tangent = function() {
	return new Vector2D( this.y, -this.x );
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Rotate45 = function() {
	return new Vector2D( (this.x + this.y) * Real_Sin45, (this.y - this.x) * Real_Sin45 );
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.RotateNegative45 = function() {
	return new Vector2D( (this.x - this.y) * Real_Sin45, (this.y + this.x) * Real_Sin45 );
}
// - -------------------------------------------------------------------------------------------------------------- - //

// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Dot = function( vs ) {
	return (this.x * vs.x) + (this.y * vs.y);
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Mix = function( vs, alpha ) {
	var Copy = new Vector2D( this );
	return Copy.MultScalar(1 - alpha).Add( vs.MultScalar(alpha) );
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.SumOf = function() {
	return this.x + this.y;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.ProductOf = function() {
	return this.x * this.y;
}
// - -------------------------------------------------------------------------------------------------------------- - //

// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Manhattan = function() {
	return Math.abs(this.x) + Math.abs(this.y);
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.MagnitudeSquared = function() {
	return this.x + this.y;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Magnitude = function() {
	return Math.sqrt( this.x + this.y );
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Normalize = function() {
	var Mag = Magnitude();
	
	if ( Mag <= 0 ) {
		this.x = 0;
		this.y = 0;
		return this;
	}
	
	this.x /= Mag;
	this.y /= Mag;
	return this;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.NormalizeRet = function() {
	var Mag = Magnitude();
	
	if ( Mag <= 0 ) {
		this.x = 0;
		this.y = 0;
		return Mag;
	}
	
	this.x /= Mag;
	this.y /= Mag;
	return Mag;
}
// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.Normal = function() {
	var Copy = new Vector2D( this );
	Copy.Normalize();
	return Copy;
}
// - -------------------------------------------------------------------------------------------------------------- - //

// - -------------------------------------------------------------------------------------------------------------- - //
Vector2D.prototype.toString = function() {
	return "(" + this.x + ", " + this.y + ")";
}
// - -------------------------------------------------------------------------------------------------------------- - //


// - -------------------------------------------------------------------------------------------------------------- - //
// "Operators" - Not actually, but they provide improved syntax by calling builtin functions //
// - -------------------------------------------------------------------------------------------------------------- - //
function Add( a, b ) {
	var Copy = a;
	Copy.Add(b);
	return Copy;
}
// - -------------------------------------------------------------------------------------------------------------- - //
function Sub( a, b ) {
	var Copy = a;
	Copy.Sub(b);
	return Copy;
}
// - -------------------------------------------------------------------------------------------------------------- - //
function Mult( a, b ) {
	var Copy = a;
	Copy.Mult(b);
	return Copy;
}
// - -------------------------------------------------------------------------------------------------------------- - //
function Div( a, b ) {
	var Copy = a;
	Copy.Div(b);
	return Copy;
}
// - -------------------------------------------------------------------------------------------------------------- - //

// - -------------------------------------------------------------------------------------------------------------- - //
function AddScalar( a, b ) {
	var Copy = a;
	Copy.AddScalar(b);
	return Copy;
}
// - -------------------------------------------------------------------------------------------------------------- - //
function SubScalar( a, b ) {
	var Copy = a;
	Copy.SubScalar(b);
	return Copy;
}
// - -------------------------------------------------------------------------------------------------------------- - //
function MultScalar( a, b ) {
	var Copy = a;
	Copy.MultScalar(b);
	return Copy;
}
// - -------------------------------------------------------------------------------------------------------------- - //
function DivScalar( a, b ) {
	var Copy = a;
	Copy.DivScalar(b);
	return Copy;
}
// - -------------------------------------------------------------------------------------------------------------- - //

// - -------------------------------------------------------------------------------------------------------------- - //
function Dot( a, b ) {
	return a.Dot(b);
}
// - -------------------------------------------------------------------------------------------------------------- - //
function Cross( a, b ) {
	return a.Cross(b);
}
// - -------------------------------------------------------------------------------------------------------------- - //
function Mix( a, b, alpha ) {
	return a.Mix(b, alpha);
}
// - -------------------------------------------------------------------------------------------------------------- - //

